344B - Simple Molecules - CodeForces Solution


brute force graphs math *1200

Please click on ads to support us..

Python Code:

a, b, c = [int(x) for x in input().split()]

z = (int)(1/2 * (c+b-a))
y = (int)(b - z)
x = (int)(a - y)

imposible = False

if (c+b-a) % 2 != 0:
    imposible = True
elif (a+b+c) % 2 != 0:
    imposible = True
elif (x < 0 or y < 0 or z < 0):
    imposible = True

if (imposible):
    print("Impossible")
else:
    print(y, z, x)
					 	  		 	   		 			 		 				

C++ Code:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

void solve() {
  int a, b, c;

  cin >> a >> b >> c;

  int fx = -1, y, z;
  for (int x = 0; x <= a; ++x) {
    z = a - x;
    y =  b - x;
    if (z >= 0 && y >= 0 && c - z == y && z + y == c && x + y == b && z + x == a) {
      fx = x;
      break;
    }
  }

  if (fx == -1) {
    cout << "Impossible";
    return;
  }

  cout << fx << ' ' << y << ' ' << z;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int t = 1;
  // cin >> t;
  while (t--) solve();

  return 0;
}
 			   		  		  	 				      	


Comments

Submit
0 Comments
More Questions

1031A - Golden Plate
1559C - Mocha and Hiking
427B - Prison Transfer
330A - Cakeminator
426A - Sereja and Mugs
363A - Soroban
1585C - Minimize Distance
1506E - Restoring the Permutation
1539A - Contest Start
363D - Renting Bikes
1198D - Rectangle Painting 1
1023B - Pair of Toys
1725A - Accumulation of Dominoes
1675E - Replace With the Previous Minimize
839A - Arya and Bran
16B - Burglar and Matches
1625B - Elementary Particles
1725G - Garage
1725B - Basketball Together
735A - Ostap and Grasshopper
1183B - Equalize Prices
1481A - Space Navigation
1437B - Reverse Binary Strings
1362B - Johnny and His Hobbies
1299A - Anu Has a Function
1111A - Superhero Transformation
954A - Diagonal Walking
39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction